import { h, render } from "vue";
import End from "./End.vue";

export default function registerSection(lf) {
  lf.register("end", ({ HtmlNode, HtmlNodeModel }) => {
    class ConnectNode extends HtmlNode {
      setHtml(rootEl) {
        rootEl.innerHTML = "";

        //创建一个空的div
        const el = document.createElement("div");

        const Profile = h(End);
        render(Profile, el);
        rootEl.appendChild(el);
      }
    }
    class ConnectNodeModel extends HtmlNodeModel {
      setAttributes() {
        this.menu = [];
      }
      initNodeData(data) {
        data.text = {
          editable: false,
        };
        super.initNodeData(data);
        const width = 100;
        const height = 40;
        this.width = width;
        this.height = height;
      }
      getConnectedSourceRules() {
        const rules = super.getConnectedSourceRules();
        const newRule = {
          message: "结束节点只能连入，不能连出！",
          validate: () => false,
        };
        rules.push(newRule);
        return rules;
      }
    }
    return {
      type: "section",
      view: ConnectNode,
      model: ConnectNodeModel,
    };
  });
}
